package com.kylin.rest.controller;


import com.kylin.rest.annotation.Pass;
import com.kylin.rest.base.PublicResultConstant;
import com.kylin.rest.service.IRedisService;
import com.kylin.rest.service.IUserService;
import com.kylin.rest.annotation.CurrentUser;
import com.kylin.rest.base.PublicResult;
import com.kylin.rest.entity.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liugh
 * @since 2018-05-03
 */
@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IRedisService redisService;

    @RequiresPermissions(value = {"user:list"})
    @GetMapping("/findUserById")
    public PublicResult<User> findUserById( @CurrentUser User currentUser) throws Exception{
        User user = userService.selectById(currentUser.getId());
        return new PublicResult<>(PublicResultConstant.SUCCESS, user);
    }

    @GetMapping("/testRedis")
    @Pass
    public PublicResult<User> testRedis( ) throws Exception{
        redisService.set("name","liugh");
        redisService.expire("name",10);
        return new PublicResult<>(PublicResultConstant.SUCCESS, null);
    }

}

